import {Obj} from "@/pages/wordPage/src/interface/Obj";
import screen from "@/pages/wordPage/src/screen";

export class scanResize extends Obj{
    ctx;
    maxTime;
    x;
    y;
    width=200;
    height=100;
    name="窗口移动标识"
    r;
    g;
    b;
    zIndex=10;
    constructor(ctx) {
        super();
        this.ctx=ctx;
        // screen.objList.push(this);
        this.maxTime=Date.now()+3000;
        this. r = Math.floor(Math.random() * 255); // RGB 需为整数
        this.  g = Math.floor(Math.random() * 255);
        this.  b = Math.floor(Math.random() * 255);
    }
    draw(p) {
        super.draw(p);


        p.fill(`rgba(${this.r}, ${this.g}, ${this.b}, 0.71)`); // 使用反引号 ``
        p.strokeWeight(2)
        p.rectMode(p.CENTER)
        p.rect(screen.width/2,screen.height/2,200,50,5)
        p.textAlign(p.CENTER,p.CENTER);
        p.textSize(32);
        p.text("窗口已载入！",screen.width/2,screen.height/2,this.width,this.height)

        if (Date.now()>this.maxTime){
            screen.objList= screen.objList.filter(d=>{
                if (d==this)return false;
                return true;
            })
            return;
        }

    }
    onClick() {
        super.onClick();
        this.maxTime=Date.now()-100;
    }

}